home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / ui / scrollfunc.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  8.9 KB  |  244 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. # Local
  23. from base.g import *
  24. from base import utils
  25.  
  26. # Qt
  27. from qt import *
  28. from scrollview import ScrollView
  29.  
  30. # Std Lib
  31. import os.path, os
  32.  
  33. class ScrollFunctionsView(ScrollView):
  34.     def __init__(self, cmd_print, cmd_print_int,
  35.                        cmd_scan, cmd_scan_int,
  36.                        cmd_pcard, cmd_pcard_int,
  37.                        cmd_fax, cmd_fax_int,
  38.                        cmd_copy, cmd_copy_int,
  39.                        parent = None,form=None, name = None,fl = 0):
  40.         
  41.         ScrollView.__init__(self,parent,name,fl)
  42.         
  43.         self.cmd_print = cmd_print
  44.         self.cmd_print_int = cmd_print_int
  45.         
  46.         self.cmd_scan = cmd_scan
  47.         self.cmd_scan_int = cmd_scan_int
  48.         
  49.         self.cmd_copy = cmd_copy
  50.         self.cmd_copy_int = cmd_copy_int
  51.         
  52.         self.cmd_pcard = cmd_pcard
  53.         self.cmd_pcard_int = cmd_pcard_int
  54.         
  55.         self.cmd_fax = cmd_fax
  56.         self.cmd_fax_int = cmd_fax_int
  57.         
  58.         self.form = form
  59.         
  60.         self.ScanPixmap = QPixmap(os.path.join(prop.image_dir, "scan_icon.png"))
  61.         self.PrintPixmap = QPixmap(os.path.join(prop.image_dir, "print_icon.png"))
  62.         self.SendFaxPixmap =QPixmap(os.path.join(prop.image_dir, "fax_icon.png"))
  63.         self.PhotoCardPixmap = QPixmap(os.path.join(prop.image_dir, "pcard_icon.png"))
  64.         self.MakeCopiesPixmap = QPixmap(os.path.join(prop.image_dir, "makecopies_icon.png"))
  65.  
  66.     def setCmds(self, cmd_print, cmd_scan, cmd_pcard, cmd_fax, cmd_copy):
  67.         self.cmd_print = cmd_print
  68.         self.cmd_scan = cmd_scan
  69.         self.cmd_copy = cmd_copy
  70.         self.cmd_pcard = cmd_pcard
  71.         self.cmd_fax = cmd_fax
  72.  
  73.     def fillControls(self):
  74.         ScrollView.fillControls(self)
  75.         
  76.         if self.cur_device is not None and \
  77.             self.cur_device.supported and \
  78.             self.cur_device.device_state != DEVICE_STATE_NOT_FOUND:
  79.         
  80.             if self.cmd_print_int:
  81.                 s = self.__tr("Print >>")
  82.             else:
  83.                 s = self.__tr("Print...")
  84.                 
  85.             self.addItem(self.__tr("<b>Print</b>"), self.__tr("Print documents or files."), 
  86.                 s, self.PrintPixmap, self.PrintButton_clicked)
  87.     
  88.             if self.cur_device.scan_type:
  89.                 if self.cmd_scan_int:
  90.                     s = self.__tr("Scan >>")
  91.                 else:
  92.                     s = self.__tr("Scan...")
  93.                     
  94.                 self.addItem(self.__tr("<b>Scan</b>"), self.__tr("Scan a document or image."),
  95.                     s, self.ScanPixmap, self.ScanButton_clicked)
  96.     
  97.             if self.cur_device.fax_type:
  98.                 if self.cmd_fax_int:
  99.                     s = self.__tr("Send PC Fax >>")
  100.                 else:
  101.                     s = self.__tr("Send PC Fax...")
  102.                     
  103.                 self.addItem(self.__tr("<b>Send PC Fax</b>"), self.__tr("Send a fax from the PC."),
  104.                     s, self.SendFaxPixmap, self.SendFaxButton_clicked)
  105.     
  106.             if self.cur_device.copy_type:
  107.                 if self.cmd_copy_int:
  108.                     s = self.__tr("Make Copies >>")
  109.                 else:
  110.                     s = self.__tr("Make Copies...")
  111.                     
  112.                 self.addItem(self.__tr("<b>Make Copies</b>"), self.__tr("Make copies"),
  113.                     s, self.MakeCopiesPixmap, self.MakeCopiesButton_clicked)
  114.     
  115.             if self.cur_device.pcard_type:
  116.                 if self.cmd_pcard_int:
  117.                     s = self.__tr("Unload Photo Card >>")
  118.                 else:
  119.                     s = self.__tr("Unload Photo Card...")
  120.                     
  121.                 self.addItem(self.__tr("<b>Unload Photo Card</b>"), self.__tr("Copy images the device to the PC."),
  122.                     s, self.PhotoCardPixmap, self.PCardButton_clicked)
  123.  
  124.         else:
  125.             if not self.cur_device.supported:
  126.                 self.addGroupHeading("not_supported", self.__tr("ERROR: Device not supported."))
  127.             else:
  128.                 self.addGroupHeading("not_found", self.__tr("ERROR: Device not found. Please check connection and power-on device."))
  129.  
  130.     def PrintButton_clicked(self):
  131.         if self.cmd_print_int:
  132.             self.form.SwitchFunctionsTab("print")
  133.         else:
  134.             self.RunCommand(self.cmd_print)
  135.             
  136.     def ScanButton_clicked(self):
  137.         if self.cmd_scan_int:
  138.             self.form.SwitchFunctionsTab("scan")
  139.         else:
  140.             self.RunCommand(self.cmd_scan)
  141.  
  142.     def PCardButton_clicked(self):
  143.         if self.cur_device.pcard_type == PCARD_TYPE_MLC:
  144.             if self.cmd_pcard_int:
  145.                 self.form.SwitchFunctionsTab("pcard")
  146.             else:
  147.                 self.RunCommand(self.cmd_pcard)
  148.  
  149.         elif self.cur_device.pcard_type == PCARD_TYPE_USB_MASS_STORAGE:
  150.             self.FailureUI(self.__tr("<p><b>Photocards on your printer are only available by mounting them as drives using USB mass storage.</b><p>Please refer to your distribution's documentation for setup and usage instructions."))
  151.  
  152.     def SendFaxButton_clicked(self):
  153.         if self.cmd_fax_int:
  154.             self.form.SwitchFunctionsTab("fax")
  155.         else:
  156.             self.RunCommand(self.cmd_fax)
  157.  
  158.     def MakeCopiesButton_clicked(self):
  159.         if self.cmd_copy_int:
  160.             self.form.SwitchFunctionsTab("copy")
  161.         else:
  162.             self.RunCommand(self.cmd_copy)
  163.  
  164.     def RunCommand(self, cmd, macro_char='%'):
  165.         QApplication.setOverrideCursor(QApplication.waitCursor)
  166.  
  167.         try:
  168.             if len(cmd) == 0:
  169.                 self.FailureUI(self.__tr("<p><b>Unable to run command. No command specified.</b><p>Use <pre>Configure...</pre> to specify a command to run."))
  170.                 log.error("No command specified. Use settings to configure commands.")
  171.             else:
  172.                 log.debug(utils.bold("Run: %s %s (%s) %s" % ("*"*20, cmd, self.cur_device.device_uri, "*"*20)))
  173.                 log.debug(cmd)
  174.                 cmd = ''.join([self.cur_device.device_vars.get(x, x) \
  175.                                  for x in cmd.split(macro_char)])
  176.                 log.debug(cmd)
  177.  
  178.                 path = cmd.split()[0]
  179.                 args = cmd.split()
  180.  
  181.                 log.debug(path)
  182.                 log.debug(args)
  183.  
  184.                 self.CleanupChildren()
  185.                 os.spawnvp(os.P_NOWAIT, path, args)
  186.  
  187.         finally:
  188.             QApplication.restoreOverrideCursor()
  189.  
  190.     def CleanupChildren(self):
  191.         log.debug("Cleaning up child processes.")
  192.         try:
  193.             os.waitpid(-1, os.WNOHANG)
  194.         except OSError:
  195.             pass
  196.  
  197.     def addItem(self, title, text, button_text, pixmap, button_func):
  198.         widget = self.getWidget()
  199.                 
  200.         self.addGroupHeading(title, title)
  201.         
  202.         layout1 = QGridLayout(widget, 1, 3, 5, 10,"layout1")
  203.         
  204.         layout1.setColStretch(0, 1)
  205.         layout1.setColStretch(1, 10)
  206.         layout1.setColStretch(2, 2)
  207.  
  208.         pushButton = QPushButton(widget, "pushButton")
  209.         pushButton.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed, 0, 0,
  210.             pushButton.sizePolicy().hasHeightForWidth()))
  211.  
  212.         layout1.addWidget(pushButton, 0, 3)
  213.  
  214.         icon = QLabel(widget, "icon")
  215.         icon.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0,
  216.             icon.sizePolicy().hasHeightForWidth()))
  217.  
  218.         icon.setMinimumSize(QSize(32, 32))
  219.         icon.setMaximumSize(QSize(32, 32))
  220.         icon.setScaledContents(1)
  221.         layout1.addWidget(icon, 0, 0)
  222.  
  223.         textLabel = QLabel(widget, "textLabel")
  224.         textLabel.setAlignment(QLabel.WordBreak)
  225.         textLabel.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred, 0, 0,
  226.             textLabel.sizePolicy().hasHeightForWidth()))        
  227.         textLabel.setFrameShape(self.frame_shape)
  228.         layout1.addWidget(textLabel, 0, 1)
  229.  
  230.         spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  231.         layout1.addItem(spacer1, 0, 2)
  232.  
  233.         textLabel.setText(text)
  234.         pushButton.setText(button_text)
  235.         icon.setPixmap(pixmap)
  236.  
  237.         self.connect(pushButton, SIGNAL("clicked()"), button_func)
  238.  
  239.         self.addWidget(widget, str(title))
  240.  
  241.  
  242.     def __tr(self,s,c = None):
  243.         return qApp.translate("DevMgr4",s,c)
  244.